package com.itheima04;

import java.util.function.Consumer;

public class ConsumerDemo {
    public static void main(String[] args) {
        operatorString("会长", s -> System.out.println(s));
//        operatorString("是的方式分", System.out::println);

        operatorString("是的防护", s -> System.out.println(new StringBuffer(s).reverse().toString()));

        System.out.println("--------");

        operatorString("是的方式地方", s -> System.out.println(s), s -> System.out.println(new StringBuffer(s).reverse().toString()));
    }

    // 定义一个方法，用不同的方式，消费字符串数据两次
    private static void operatorString(String s, Consumer<String> c1, Consumer<String> c2) {
//        c1.accept(s);
//        c2.accept(s);
        c1.andThen(c2).accept(s);
    }

    // 定义一个方法，消费字符串数据
    private static void operatorString(String s, Consumer<String> c) {
        c.accept(s);
    }
}
